<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
    <meta charset="utf-8">
    <meta name="decorator" content="default" />
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <!-- 新建定制子项目 -->
    <title><spring:message code="custom_create_sub_item_title"/></title>
    <script type="text/javascript">
        window.onload = function(){
            var windowH = window.innerHeight || document.documentElement.clientHeight
                    || document.body.clientHeight
            $('.middle').css('height', windowH - 40);

        }
        // 父框index
        var parentFrameIndex = 1;

        // 初始加载
        $(document).ready(function(){

        });


        // 保存方法
        var saveForm = {
            s:null,
            t:null,
            save:function(s,t){
                $(t).attr("disabled",true);
                this.s=s;
                this.t=t;
                if($('#itemCD').val().trim() == $('#itemValue').val().trim()){
                    // 定制子项项目值重复，请重新输入！
                    layer.msg('<spring:message code="custom_code_value_not_repeate_alert"/>', {time:2000});
                    $(saveForm.t).attr("disabled",false);
                    return;
                }
                // 子项值是否重复
                var result = window.parent.frames[parentFrameIndex].isSubItemValueRepeate($('#itemValue').val(),$("#delIndex").val());

                if (result == true) {

                    // 定制子项项目值重复，请重新输入！
                    layer.msg('<spring:message code="custom_sub_item_repeate_alert"/>', {time:1000});
                    $(saveForm.t).attr("disabled",false);
                    return;

                }

                $("#inputForm").validate({
                    submitHandler : function() {
                        // 格式化，去除逗号
                        formUnFormat($("#inputForm"));

                        var params = $("#inputForm").serialize();
                        $.post("${ctx}/custom/customitem/saveSub", params, function(result) {
                            if (result == "false") {
                                $("#inputForm")[0].reset();
                                $(saveForm.t).attr("disabled",false);
                            } else {

                                // 保存操作
                                if (saveForm.s == 0) {
                                    window.parent.frames[parentFrameIndex].reloadSubItem();
                                    closeWin();
                                }
                                // 保存并继续
                                else {
                                    $("#inputForm")[0].reset();
                                    $(saveForm.t).attr("disabled",false);
                                    window.parent.frames[parentFrameIndex].reloadSubItem();
                                }

                            }
                        }, 'json');
                    },
                    rules: {
                        itemValue: {remote: "${ctx}/custom/customitem/checkItemValue?oldItemValue="+$("#oldItemValue").val()},
                    },
                    messages: {
                        // 定制项目值已经存在！
                        itemValue: {remote: '<spring:message code="custom_item_value_exist_alert"/>'},
                    },
                    fail: function(element,e) {
                        $(saveForm.t).attr("disabled",false);
                    }
                });
                $("#inputForm").submit();
            }
        }

    </script>
    <style>
        :root, body{
            min-width: 800px;
            position: absolute;
            height: 440px;
        }
    </style>
</head>
<body>
<form id="inputForm">
<div id="createHead" class="layerHeader clearfix" >
            <!-- 新建定制子项目 -->
                 <p class="headerTitle">
                     <spring:message code="custom_create_sub_item_title"/>
                 </p>
                <div class="headerButton clearfix">
                    <div class="clearfix">
                        <!-- 取消 -->
                        <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
                        <shiro:hasPermission name="custom:customitem:edit">
                            <!-- 保存 -->
                            <button type="button"  style="margin:0 auto;" onclick="saveForm.save(0,this)"><spring:message code="common_save"/></button>
                            <!-- 保存并继续 -->
                            <button type="button" onclick="saveForm.save(1,this)"><spring:message code="common_save_continue"/></button>
                        </shiro:hasPermission>
                    </div>
                </div>
                </div>
            <div class="tabBoxSm smOrderBox">

                    <div class="code_left col-50">
                        <div class=" items clearfix">
                            <!-- 隐藏变量 -->
                            <!-- 项目父值 -->
                            <input type="hidden"  id="itemCD" value="${design.itemCD}"  />
                            <input type="hidden"  name="delIndex" id="delIndex" value="${design.delIndex}"  />
                            <input type="hidden"  name="id" id="id" value="${design.id}"  />
                            <input type="hidden" name="haveToFlag" value="1"/>
                            <!-- 项目CD -->
                            <p class="tit"><spring:message code="custom_project_cd"/></p>
                            <p class="">${design.itemCD}</p>
                        </div>
                        <div class=" items clearfix haveToBox">
                            <!-- 项目值 -->
                            <p class="tit"><spring:message code="custom_item_value"/></p>
                            <input type="text" name="itemValue" id="itemValue" value="${design.itemValue}" maxlength="22" class="form-control" data-rule-required="true" data-msg-required="<spring:message code="custom_item_value_alert"/>"  data-rule-notEqualTo="#itemCD"  data-msg-notEqualTo="<spring:message code="custom_code_value_not_repeate_alert" />" >
                            <input type="hidden" name="oldItemValue" id="oldItemValue" value="${design.itemValue}">
                            <p class="haveTo">*</p>
                        </div>
                        <div class=" items clearfix haveToBox">
                            <!-- 中文全称 -->
                            <p class="tit"><spring:message code="custom_item_cn"/></p>
                            <input type="text" name="itemNameCN"  value="${design.itemNameCN}"  maxlength="50" class="form-control" data-rule-required="true" data-msg-required="<spring:message code="custom_item_cn_alert"/>">
                            <p class="haveTo">*</p>
                        </div>
                        <div class=" items clearfix haveToBox">
                            <!-- 英文全称 -->
                            <p class="tit"><spring:message code="custom_item_en"/></p>
                            <input type="text" name="itemNameEN"  value="${design.itemNameEN}"  maxlength="50" class="form-control" data-rule-required="true" data-msg-required="<spring:message code="custom_item_en_alert"/>">
                            <p class="haveTo">*</p>
                        </div>
                        <div class=" items clearfix haveToBox">
                            <!-- 日文全称 -->
                            <p class="tit"><spring:message code="custom_item_jp"/></p>
                            <input type="text" name="itemNameJP"  value="${design.itemNameJP}"  maxlength="50" class="form-control" data-rule-required="true" data-msg-required="<spring:message code="custom_item_jp_alert"/>">
                            <p class="haveTo">*</p>
                        </div>
                        <div class=" items clearfix ">
                                <!-- 状态 -->
                            <div class="">
                                 <p class="tit"><spring:message code="common_status"/></p>
                                <div class="labelBox">
                                    <c:choose>
                                        <c:when test="${not empty design.enableFlag}">
                                            <!-- 启用 -->
                                            <label class=""><input type="radio" name="enableFlag" value="1" class="rast" <c:if test="${design.enableFlag eq 1 }"> checked="checked"</c:if>><spring:message code="common_enable"/></label>
                                            <!-- 停用 -->
                                            <label class=""><input type="radio" name="enableFlag" value="0" class="rast" <c:if test="${design.enableFlag eq 0}"> checked="checked"</c:if>><spring:message code="common_disable"/></label>
                                        </c:when>
                                        <c:otherwise>
                                            <label class=""><input type="radio" name="enableFlag" value="1" class="rast" checked='checked'><spring:message code="common_enable"/></label>
                                            <label class=""><input type="radio" name="enableFlag" value="0" class="rast"><spring:message code="common_disable"/></label>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                            <div class="haveToBox">
                                <!-- 项目费用 -->
                                <p class="tit"><spring:message code="custom_item_cost"/></p>
                                <!-- 请输入正确项目费用 -->
                                <input type="tel" name="itemCost" style="width:94px;"
                                       value="<fmt:formatNumber value="${design.itemCost}" pattern="#,##0.00#"/>"
                                       class="form-control" onblur="formatMoney(this,2)"
                                       data-rule-min="0" data-msg-min="<spring:message code="custom_right_cost_alert"/>"
                                       data-rule-required="true"  data-msg-required="<spring:message code="custom_cost_alert"/>"
                                       data-rule-integerDecimalmax='5.2' data-msg-integerDecimalmax="<spring:message code="custom_right_cost_alert"/>">
                                <p class="haveTo">*</p>
                            </div>
                        </div>
                        <div class="items clearfix">
                            <!-- 描述 -->
                                <p style="float: left;width: 85px"><spring:message code="custom_describe"/>
                                    <span >(0/100)</span>
                                </p>
                            <div>
                                <!-- 请输入描述内容 -->
                                <textarea name="remarks" value="${design.remarks}"  style="width: 380px" maxlength="100">${design.remarks}</textarea>
                            </div>
                        </div>
                    </div>
                    <div class="code_right col-50" >
                        <div class= "tabBoxSm" style="border: 1px solid #B7B9B8; ">
                        <!-- 上传图片 -->
                        <input type="hidden" name="fileId" value="${design.uploadFile.id}" >
                        <input  id="nameImage" type="hidden" name="filePath" value="${design.uploadFile.showImgUrl}"  htmlEscape="false" maxlength="255" class="input-xlarge" data-msg-required="<spring:message code="custom_img_url"/>" />
                        <sys:ckfinder input="nameImage" type="images" uploadPath="/custom" selectMultiple="false" maxWidth="200" maxHeight="200"/>
                        </div>
                        <div class="tabBoxSm "style="height: 174px">&nbsp;</div>
                    </div>
</div>
</form>
</body>
</html>